package cn.tedu.service;

import cn.tedu.mapper.HouseResourcesMapper;
import cn.tedu.pojo.HouseResources;
import cn.tedu.vo.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author:努力学java的小雨
 * @创建时间:2021/9/27 17:23
 */
@Service
public class HouseResourceServiceImpl implements HouseResourcesService{
    @Autowired
    private HouseResourcesMapper houseResourcesMapper;

    //分页查询房源列表
    @Override
    public PageResult houseResourcesFindAll(PageResult pageResult) {
        IPage<HouseResources> page=new Page<>();
        page.setCurrent(pageResult.getPageNum()).setSize(pageResult.getPageSize());
        QueryWrapper<HouseResources> queryWrapper = new QueryWrapper<>();
        boolean flag= StringUtils.hasLength(pageResult.getQuery());
        queryWrapper.like(flag,"title",pageResult.getQuery());
        page=houseResourcesMapper.selectPage(page,queryWrapper);
        pageResult.setTotal(page.getTotal()).setRows(page.getRecords());
        return pageResult;
    }

    //更改房源状态
    @Override
    public void updateStatus(HouseResources houseResources) {
        houseResourcesMapper.updateById(houseResources);
    }

    //查询房源状态
    @Override
    public HouseResources findStatus(Integer id) {
        HouseResources houseResources = houseResourcesMapper.selectById(id);
        return houseResources;
    }

    //回显房源数据
    @Override
    public HouseResources findHouse(Integer id) {
        HouseResources houseResources=houseResourcesMapper.selectById(id);
        return houseResources;
    }

    //更改房源信息
    @Override
    public void updateHouseResource(HouseResources houseResources) {
        houseResourcesMapper.updateById(houseResources);
    }
}
